home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6052 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  76 lines

  1. Path: news.uh.edu!usenet
  2. From: Sensarn <txs53132@bayou.uh.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Graphics
  5. Date: 10 Feb 1996 04:12:59 GMT
  6. Organization: AEtna Insurance Agency
  7. Message-ID: <4fh60b$hc9@masala.cc.uh.edu>
  8. References: <4fe99q$s2s@newsbf02.news.aol.com>
  9. NNTP-Posting-Host: sip-14122.public-dialups.uh.edu
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1 (Windows; U; 16bit)
  14.  
  15. First of all, you need to access the video buffer.  This is located in 
  16. segment A000.  I would strongly suggest starting with mode 13h.  Here is 
  17. how to call it:
  18.  
  19. //via BIOS
  20. union REGS inregs, outregs;
  21. inregs.x.ax=0x13;
  22. int86(0x10,&inregs,&outregs);
  23.  
  24. //via inline assembler
  25. asm {
  26.     mov ax,0x13
  27.     int 0x10
  28. }
  29.  
  30. To set a pointer that can allow ease of video access, use this:
  31.  
  32. unsigned char far *video_buffer=(unsigned char far *)0xA0000000;
  33.  
  34. You now have a FAR pointer to A000:0000h, the beginning of the video 
  35. buffer.  To plot a pixel, you use this formula:
  36.  
  37. video_buffer[y*320+x]=color;
  38.  
  39. Use binary shifting for speed:
  40.  
  41. video_buffer[(y<<8)+(y<<6)+x]=color;
  42.  
  43. To create a virtual screen (double buffer), use this declaration and 
  44. initialization:
  45.  
  46. unsigned char *double_buffer=(unsigned char far *)far_malloc(64001);
  47.  
  48. You have now allocated a full-screen double buffer.  To display it, you 
  49. can either use memcpy, or pure assembly (assembly is recommended because 
  50. it's faster):
  51.  
  52. asm {
  53.     les di,video_buffer
  54.     lds si,double_buffer
  55.     cld
  56.     mov cx,32000
  57.     rep movsw
  58. }
  59.  
  60. That example simply stores the segment and offset of video_buffer into 
  61. ES:DI (extra segment and destiny index -- destination) and the segment 
  62. and offset of double_buffer into DS:SI (data segment and source index -- 
  63. source).  It clears the direction flag (just in case we're facing 
  64. backward -- we don't want that) and writes 32000 words (a full screen) 
  65. from the double buffer to the video buffer.  Wow!  You can copy the 
  66. screen to the double buffer by storing double_buffer in ES:DI and 
  67. video_buffer in DS:SI.
  68.     If you have any specific questions, feel free to ask them.
  69.  
  70. -- 
  71. |\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\|
  72. Steven Sensarn -- txs53132@bayou.uh.edu
  73. |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
  74.  
  75.  
  76.